<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>实现底部导航栏</title>
  <link rel="stylesheet" href="css/nav.css">
</head>

<body>

  <div id="app">
    <div class="content">
      <h1>主页内容</h1>
    </div>
    <!-- TODO 根据HTML结构分析，定义子组件结构 -->
    <footer-father></footer-father>
  </div>

  <template id="footerFather">
    <div class="bottom-navbar">

      <footer-son v-for="nav in navTabs" :title="nav.title" :icon="nav.icon"></footer-son>
    </div>
  </template>
  <template id="footerSon">
    <div class="navbar-item"><img :src="icon" :alt="title"> <span>{{title}}</span></div>
  </template>

  <!-- 引入 Vue.js -->
  <script src="js/vue.js"></script>
  <script>
    var footerSon = {
      template: '#footerSon',
      props: ['title', 'icon']
    }

    var footerFather = {
      template: '#footerFather',
      components: {
        'FooterSon': footerSon
      },
      data() {
        return {
          navTabs: [
            { title: '首页', icon: 'images/nav-icon-home.png' },
            { title: '商品分类', icon: 'images/nav-icon-category.png' },
            { title: '购物车', icon: 'images/nav-icon-cart.png' },
            { title: '个人中心', icon: 'images/nav-icon-user.png' }
          ]
        }
      }
    }

    new Vue({
      el: '#app',
      components: {
        'FooterFather': footerFather
      }
    })
  </script>

</body>

</html>